package icu.qx.wm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import icu.qx.wm.vo.ProWorkOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import icu.qx.wm.domain.WmProductReceipt;
import icu.qx.wm.service.IWmProductReceiptService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 产品入库单Controller
 *
 * @author ruoyi
 * &#064;date  2024-06-17
 */
@RestController
@RequestMapping("/wm/inbound/product_receipt")
public class WmProductReceiptController extends BaseController {
    private final IWmProductReceiptService wmProductReceiptService;

    @Autowired
    public WmProductReceiptController(IWmProductReceiptService wmProductReceiptService) {
        this.wmProductReceiptService = wmProductReceiptService;
    }

    /**
     * 查询产品入库单列表
     */
    @RequiresPermissions("wm:inbound:product_receipt:list")
    @GetMapping("/list")
    public TableDataInfo list(WmProductReceipt wmProductReceipt) {
        startPage();
        List<WmProductReceipt> list = wmProductReceiptService.selectWmProductReceiptList(wmProductReceipt);
        return getDataTable(list);
    }

    /**
     * 导出产品入库单列表
     */
    @RequiresPermissions("wm:inbound:product_receipt:export")
    @Log(title = "产品入库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmProductReceipt wmProductReceipt) {
        List<WmProductReceipt> list = wmProductReceiptService.selectWmProductReceiptList(wmProductReceipt);
        ExcelUtil<WmProductReceipt> util = new ExcelUtil<>(WmProductReceipt.class);
        util.exportExcel(response, list, "产品入库单数据");
    }

    /**
     * 获取产品入库单详细信息
     */
    @RequiresPermissions("wm:inbound:product_receipt:query")
    @GetMapping(value = "/{prCode}")
    public AjaxResult getInfo(@PathVariable("prCode") String prCode) {
        return success(wmProductReceiptService.selectWmProductReceiptByPrCode(prCode));
    }

    /**
     * 新增产品入库单
     */
    @RequiresPermissions("wm:inbound:product_receipt:add")
    @Log(title = "产品入库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmProductReceipt wmProductReceipt) {
        return toAjax(wmProductReceiptService.insertWmProductReceipt(wmProductReceipt));
    }

    /**
     * 修改产品入库单
     */
    @RequiresPermissions("wm:inbound:product_receipt:edit")
    @Log(title = "产品入库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmProductReceipt wmProductReceipt) {
        return toAjax(wmProductReceiptService.updateWmProductReceipt(wmProductReceipt));
    }

    /**
     * 产品入库
     */
    @RequiresPermissions("wm:inbound:product_receipt:store")
    @Log(title = "产品入库单", businessType = BusinessType.UPDATE)
    @PutMapping("/store")
    public AjaxResult store(@RequestBody WmProductReceipt wmProductReceipt) {
        return toAjax(wmProductReceiptService.storeWmProductReceipt(wmProductReceipt));
    }

    /**
     * 删除产品入库单
     */
    @RequiresPermissions("wm:inbound:product_receipt:remove")
    @Log(title = "产品入库单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{prCodes}")
    public AjaxResult remove(@PathVariable String[] prCodes) {
        return toAjax(wmProductReceiptService.deleteWmProductReceiptByPrCodes(prCodes));
    }

    /**
     * 查询工单
     */
    @RequiresPermissions("wm:inbound:product_receipt:list")
    @GetMapping("/order/list")
    public TableDataInfo selectWorkOrder(ProWorkOrderVo proWorkOrderVo) {
        startPage();
        List<ProWorkOrderVo> list = wmProductReceiptService.selectWorkOrder(proWorkOrderVo);
        return getDataTable(list);
    }
}
